import { ref } from 'vue';
import type { uni_type_props } from '../../uni_type/Classes/cla_uni_type_props';

export const ref_selectable_type_info = ref<uni_type_props[]>([
  { id: 'type_156', val: '音乐', active: false },
  { id: 'type_157', val: '话剧', active: false },
  { id: 'type_158', val: '动画', active: false },
  { id: 'type_159', val: '舞蹈', active: false },
  { id: 'type_160', val: '声乐', active: false },
  { id: 'type_161', val: '吉他', active: false },
  { id: 'type_162', val: '钢琴', active: false },
  { id: 'type_163', val: '短笛', active: false },
  { id: 'type_164', val: '长笛', active: false },
  { id: 'type_165', val: '管风琴', active: false },
  { id: 'type_166', val: '爵士', active: false },
  { id: 'type_167', val: '芭蕾', active: false },
]);

/**
 * 获取 当前 数据 信息 在启用类型 的 ind
 *
 * 不在 return -1
 */
export function get_cur_uni_info_ind_in_search_type_info(info: uni_type_props) {
  for (let i = 0; i < ref_selectable_type_info.value.length; i++) {
    let cur_check = ref_selectable_type_info.value[i];

    if (cur_check.id == info.id) {
      return i;
    }
  }

  return -1;
}

/**
 * 修改当前 类型 应用状态 为 true
 */
export function active_search_type_info(info: uni_type_props) {
  change_search_type_info(info, true);
}

/**
 * 修改当前 类型 应用状态 为 false
 */
export function disactive_search_type_info(info: uni_type_props) {
  change_search_type_info(info, false);
}

function change_search_type_info(info: uni_type_props, bool: boolean) {
  let ind = get_cur_uni_info_ind_in_search_type_info(info);

  if (ind == -1) {
    return;
  }

  ref_selectable_type_info.value[ind].active = bool;
}
